import sys

#####
# 功能: 检查DRC PO.R.15
# 日期：2025-0425
# 解决了算术计算不精确，添加了 -help 功能 和 异常处理
#####

def print_help():
	help_text = """\
	element1: layer ( "p011 p008" ~> string )
	element2: width ( "" -> float )
	"""
	print(help_text)

def check_PO_odd_even(p_layer, pol_to_por):
	PO_0p011 = [0.011, 0.046]
	PO_0p008 = [0.008, 0.049]

	if p_layer == "p011":
		a = (pol_to_por-PO_0p011[0])/(PO_0p011[0]+PO_0p011[1])
		if a-int(a)>0.5:
			n = int(a)+1
		else:
			n = int(a)
	elif p_layer == "p008":
		a = (pol_to_por-PO_0p008[0])/(PO_0p008[0]+PO_0p008[1])
		if a-int(a)>0.5:
			n = int(a)+1
		else:
			n = int(a)
	if (n+1)%2 == 1:
		print("odd")
	else:
		print("even")
	print(n+1)


if __name__ == "__main__" :
	try:
		p_layer = sys.argv[1]
		PO_all_width = sys.argv[2]

		print("Check DRC : PO.R.15")

		if '-h' in sys.argv  or '--help' in sys.argv: 
			print_help()
		else:
			check_PO_odd_even(p_layer, float(PO_all_width))
	except:
		print_help()
